﻿/*
 * Cratos Tools - General
 * Cratos Entity Access Base class
 * 
 * Copyright (c) 2011-2012 Draco
 * 
 * This file is part of Cratos.
 * 
 * Cratos is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Cratos is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Cratos.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *       .==.        .==.
 *      //'^\\      //^'\\
 *     // ^ ^\(\__/)/^ ^^\\
 *    //^ ^^ ^/6  6\ ^^ ^ \\
 *   //^ ^^ ^/( .. )\^ ^ ^ \\
 *  // ^^ ^/\| V""V|/\^ ^ ^ \\
 * //^^/\/ /  '~~'  \ \/\^ ^ \\
 *  ------------------------------------
 *  HERE BE DRAGONS
 *  
 *  Johan Dercksen - johan@draco.co.za
 */
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;

using Cratos.Tools.General;

namespace Cratos.Server.Entity
{
	/// <summary>
	/// Cratos Entity Base class
	/// </summary>
	public abstract class CratosEntityBase : CratosEntityDatabase, IDisposable, ICratosEntityAccess
	{
		#region Class Constant declarations
		#endregion

		#region Class Event declarations
		#endregion

		#region Class Variable declarations
		private bool										isDisposed;
		private Collection<CratosError> entityErrors = new Collection<CratosError>();
		#endregion

		#region Class Constructors & Destructors
		/// <summary>
		/// Class Constructor
		/// </summary>
		public CratosEntityBase() { }

		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or
		/// resetting unmanaged resources.
		/// </summary>
		public void Dispose() { Dispose(true); GC.SuppressFinalize(this); }

		/// <summary>
		/// Dispose method doing the disposing
		/// </summary>
		/// <param name="isDisposing"></param>
		protected virtual void Dispose(bool isDisposing)
		{
			// Declare the required variables

			// Check to see if Dispose has already been called.
			if (!this.isDisposed)
			{
				// Dispose the objects if required
				if (isDisposing)
				{
					// Dispose of the required objects
					//if (this.DBAccess != null) { this.DBAccess.Disconnect(); this.DBAccess = null; }
				}
			}

			// Set the disposed indicator
			this.isDisposed = true;

			// Return to calling method
			return;
		}
		#endregion

		#region Class Properties
		/// <summary>
		/// Ignore Unity Indicator
		/// </summary>
		public bool IgnoreUnity { get; set; }

		/// <summary>
		/// Cratos Entity Error Collection
		/// </summary>
		public Collection<CratosError> Errors
		{
			get { return (this.entityErrors); }
		}
		#endregion

		#region Class Methods
		/// <summary>
		/// Entity Perform Action
		/// </summary>
		/// <returns>A Boolean indicating success of the method</returns>
		public abstract bool PerformAction(ref IDOCratos cratosDO);
		#endregion

		#region Class Support Methods
		#endregion
	}
}
